#ifndef UTIL_H
#define UTIL_H

// Do I really need this on .h????
#include <vector>
#include <list>

#include "contest_interface.h"

#define MIN_VARCHAR ""
//CHANGED 90=Z from 126=~ ... might need to revert back depending on the usage of payload
#define MAX_VARCHAR (std::string(MAX_VARCHAR_LENGTH,126)).c_str()

// Compares two attributes
int attcmp(const Attribute &a, const Attribute &b);

// Compares two keys
int keycmp(const Key &a, const Key &b);

// Returns 0 if every attribute of key a is smaller than or equal to key b
// or a value > 0 if the attribute with index i in a is greater than in b
bool CheckBounds(const Key &a, const Key &b, int *index);

// Copys key b to key a
void CopyKey(Key &a, const Key &b);

void CopyRecord(Record *dst, Record *src);

// Deletes a key
void DeleteKey(Key *key);

// Deletes a record
void DeleteRecord(Record **record);

void printValue(Record *record);

uint32_t keycmp_qtree(const Key &a, const Key &b);

int BlockCmp(const Block &a, const Block &b);

// Compares two records; a>b => 1, a<b => -1, a==b => 0
int recordCmp(const Record &a, const Record &b);

void CopyRecord(Record *dst, Key key, Block &payload);

void CopyPayload(Block &dstPayload, Block &srcPayload);

int keycmp_range(const Key &a, const Key &mx, const Key &mn);

// Create a new attribute of type SHORT
Attribute *ShortAttribute(int32_t value);

// Create a new attribute of type INT
Attribute *IntAttribute(int64_t value);

// Create a new attribute of type VARCHAR
Attribute *VarcharAttribute(const char* value);

// Create a record for the BasicTest
Record *CreateRecordBasic(int32_t attribute_1, int64_t attribute_2, const char* attribute_3,
        const char* payload);

// Compares the 4 attributes used in the Qtree of two records
bool recordCmpQtree(const Record &a, const Record &b);

bool BlockCmp_DataOnly(const Block a, const Block b);

// Set the value of a Block
void SetValue(Block &block, const char* value);

void keycmp_partial(const Key &a, const Key &b, std::vector< int> *ls, int s, std::list< int>* l);

int recordsCmp_partial(const Key &a, const Key &k);

int keycmp_sort(const Key &a, const Key &b);

int attcmp_(const Attribute &a, const Attribute &b);

bool keyCheckIsPartial(Key key);

// Free all resources that are currently used by record
// (this also includes the memory used to store the payload)
void Release(Record* record);

// Compare two Records
int RecordCmp(const Record& a, const Record& b);
// Compare two Keys
int KeyCmp(const Key& a, const Key& b);

// Create a new record for the RangeTest
Record *CreateRecordRange(int32_t attribute_1, const char* attribute_2, int64_t attribute_3, const char* payload);

#endif  /* UTIL_H */

